package cn.com.dcsgo.controller;


import cn.com.dcsgo.model.product.Attr;
import cn.com.dcsgo.result.Result;
import cn.com.dcsgo.service.AttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/*
接口路径及参数参考前端文件：
uu-preferred-front-end/uuyx-admin/src/api/product/attr.js
 */

/**
 * <p>
 * 商品属性 前端控制器
 * </p>
 *
 * @author Dcsgo
 * @since 2025-04-07
 */
@RestController
@Api(tags = "商品属性")
@RequiredArgsConstructor
@RequestMapping("admin/product/attr")
public class AttrController {
    public final AttrService attrService;

    @ApiOperation("通过商品属性分组id获取商品属性")
    @GetMapping("{groupId}")
    public Result<List<Attr>> getListByGroupId(@PathVariable Long groupId) {
        List<Attr> list = attrService.listByGroupId(groupId);
        return Result.ok(list);
    }

    @ApiOperation("通过id获取商品属性")
    @GetMapping("get/{id}")
    public Result<Attr> getById(@PathVariable Long id) {
        Attr attr = attrService.getById(id);
        return Result.ok(attr);
    }

    @ApiOperation("添加商品属性")
    @PostMapping("save")
    public Result<Serializable> save(@RequestBody Attr attr) {
        attrService.save(attr);
        return Result.ok(null);
    }

    @ApiOperation("通过id更新商品属性")
    @PutMapping("update")
    public Result<Serializable> updateById(@RequestBody Attr attr) {
        attrService.updateById(attr);
        return Result.ok(null);
    }

    @ApiOperation("通过id删除商品属性")
    @DeleteMapping("remove/{id}")
    public Result<Serializable> removeById(@PathVariable Long id) {
        attrService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation("通过id批量删除商品属性")
    @DeleteMapping("batchRemove")
    public Result<Serializable> removeBathByIds(@RequestBody List<Long> idList) {
        attrService.removeByIds(idList);
        return Result.ok(null);
    }
}

